<template>
  <div class="summary-cards">
    <el-card class="summary-card">
      <div class="summary-content">
        <div class="summary-icon total-investment">
          <el-icon><Money /></el-icon>
        </div>
        <div class="summary-details">
          <div class="summary-label">总投资金额</div>
          <div class="summary-value">¥{{ formatAmount(summaryData.totalInvestment) }}</div>
        </div>
      </div>
    </el-card>
    <el-card class="summary-card">
      <div class="summary-content">
        <div class="summary-icon current-value">
          <el-icon><TrendCharts /></el-icon>
        </div>
        <div class="summary-details">
          <div class="summary-label">持有资产</div>
          <div class="summary-value">¥{{ formatAmount(summaryData.currentValue) }}</div>
        </div>
      </div>
    </el-card>
    <el-card class="summary-card">
      <div class="summary-content">
        <div class="summary-icon total-profit">
          <el-icon><ProfitLoss /></el-icon>
        </div>
        <div class="summary-details">
          <div class="summary-label">累计盈亏</div>
          <div class="summary-value" :class="getProfitClass()">
            {{ formatAmount(summaryData.totalProfit, true) }}
          </div>
          <div class="profit-rate" :class="getProfitClass()">
            ({{ formatRate(summaryData.profitRate) }}%)
          </div>
        </div>
      </div>
    </el-card>
    <el-card class="summary-card">
      <div class="summary-content">
        <div class="summary-icon accumulated-earnings">
          <el-icon><Coin /></el-icon>
        </div>
        <div class="summary-details">
          <div class="summary-label">累计收益</div>
          <div class="summary-value positive">¥{{ formatAmount(summaryData.accumulatedEarnings) }}</div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { defineProps } from 'vue';
import { Money, TrendCharts, ProfitLoss, Coin } from '@element-plus/icons-vue';
import { formatAmount, formatRate } from './utils';

const props = defineProps({
  summaryData: {
    type: Object,
    required: true
  }
});

// 盈亏样式
const getProfitClass = () => {
  const profit = props.summaryData.totalProfit;
  if (profit > 0) return 'positive';
  if (profit < 0) return 'negative';
  return '';
};
</script>

<style scoped>
/* 统计卡片样式 */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.summary-card {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.summary-content {
  display: flex;
  align-items: center;
  padding: 8px;
}

.summary-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  color: white;
  font-size: 24px;
}

.summary-icon.total-investment {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.summary-icon.current-value {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.summary-icon.total-profit {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.summary-icon.accumulated-earnings {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.summary-details {
  flex: 1;
}

.summary-label {
  font-size: 14px;
  color: #8492a6;
  margin-bottom: 4px;
}

.summary-value {
  font-size: 24px;
  font-weight: 600;
  color: #303133;
}

.profit-rate {
  font-size: 12px;
  margin-top: 2px;
}

.positive {
  color: #67c23a;
}

.negative {
  color: #f56c6c;
}

@media (max-width: 768px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }
}
</style>
